/**
 *
 */

#include "config.h"


//IP addresses : Change this for your network
char ipclass[]={"192.168.30."};		//Wireless IP Class. Currently works on only IPs of a single class. If you need it to work for different classes, you will also need to modify add_init() & server_check() accordingly
char ipclass_w[]={"192.168.21."};	//Ip Class for the wiredconnection. Used for logging data.
char node[USERS][4]={"1", "4", "5", "22"}; //"2", "3", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "23", "24", "25", "26"};			//Include all IPs

struct sockaddr_in addr[USERS];			//Stores addresses of all nodes
char add[USERS][16];				//Stores addresses of all nodes in ascii format
int sockfd, hno=-1;

void add_init(int port)			//Storing addresses from ascii format to network format
{
  int i;
  for(i=0;i<USERS;i++)			//Binding the IP address together
    {
      strcpy(add[i], ipclass);
      strcat(add[i], node[i]);
    }
  for(i=0;i<USERS;i++)			//Address initialization. Network format being used is struct sockaddr_in
    {
      addr[i].sin_family = AF_INET;
      addr[i].sin_port = htons(port);
      addr[i].sin_addr.s_addr=inet_addr(add[i]);
      memset(&(addr[i].sin_zero), '\0', 8);
    }
}

int server_check(char *ch)	//Returns the id of the server (id is the index of the array add[] for all purposes)
{
  int i;
  for(i=0;i<USERS;i++)
    {				//Check who is the talker
      if(strcmp(node[i], ch)==0)
	{
	  return i;
	}
    }
  return -1;
}

struct sockaddr_in get_my_addr()	//Returns own address
{
  return addr[hno];
}

